/**
 * @author hello
 */
 function request(paras) {  
       var url = location.href;  
       var paramStr = url.substring(url.indexOf('?') + 1, url.length).split('&');  
       var j;  
       var paramObj = {};  
       for (var i = 0; j = paramStr[i]; i++) {  
           paramObj[j.substring(0, j.indexOf('=')).toLowerCase()] = j.substring(j.indexOf('=') + 1, j.length);  
       }  
         
       var returnValue=paramObj[paras.toLowerCase()];  

       if (typeof (returnValue) == "undefined") {  
           return "";  
       } else {  
           return returnValue;  
       }  
   }  
 function trim(str){
 	if(str != null)
           	return str.replace(/(^\s*)|(\s*$)/g, "");
 	else 
 		return str;
   }
 
$(document).ready(function(){
   $('#user').html(request('user'));
   
   /*
    * driverhome.js
    */
   
   $('#query_task').click(function(){
	   $.ajax({
			type:'GET',
			url: 'querytask?action=current',
			dataType: "json",
			success:function(json){
					if(json){
						$('#detail_no').html(json.no);
						$('#detail_st').html(json.starttime);
						$('#detail_dt').html(json.duetime);
						$('#detail_dn').html(json.drivername);
						$('#detail_c').html(json.comment);
					}else{
						alert('sorry,request error!');
					}
			}
		});
   })
   
   $('#report').click(function(){
	   $('#status').html('');
	   var status = trim($('#update_status').val());
	   if(status){
		   $.ajax({
				type:'POST',
				url: 'updatetask?action=update',
				dataType: "json",
				data:{"status":status},
				success:function(json){
						if(json){
							$('#status').html(json.status);
						}else{
							$('#status').html('sorry , status error!');
						}
				}
			});
	   }
   })
   $('#missionover').click(function(){
	   $('#status').html('');
	   $.ajax({
			type:'POST',
			url: 'updatetask?action=over',
			dataType: "json",
			success:function(json){
					if(json.status){
						$('#status').html(json.status);
					}else{
					}
			}
		});
   })
   
   $('#query_status').click(function(){
	   $('#status').html('');
	   $.ajax({
			type:'POST',
			url: 'querytask?action=status',
			dataType: "json",
			success:function(json){
					if(json){
						$('#status').html(json.status);
					}else{
						$('#status').html('sorry , status error!');
					}
			}
		});
   })
   
   
   $('#query_history').click(function(){
	   $.ajax({
			type:'GET',
			url: 'querytask?action=history',
			dataType: "json",
			success:function(json){
					if(json.tasks){
						var tasks = json.tasks;
						$('#history_table').dataTable({
							"bPaginate":true,
						//	"sPaginationType": "full_numbers",
							"bDestroy":true,//重新加载是设置的属性
							"bProcessing":true,
							"aaData":tasks,
							"bLengthChange":false,
							"iDisplayLength": 10,
							"bFilter":false,
							"bSort":true,
						});
					}else{
						alert('no tasks');
					}
			}
		});
   })
   
   /*
    * end of driverhome.js
    */
   
   /*
    * motohome.js
    */
   
   $('#dispatch').click(function(){
	   var no = trim($('#moto_no').val()),
	   		name = trim($('#moto_name').val()),
	   		start = trim($('#moto_start').val()),
	   		due = trim($('#moto_due').val()),
	   		comment = trim($('#moto_comment').val());
	   if(no && name && start && due && comment){
		   $.ajax({
				type:'POST',
				url: 'updatetask?action=add',
				dataType: "json",
				data:{"no":no,"name":name,"start":start,"due":due,"comment":comment},
				success:function(json){
						if(json.success == 1){
							alert('success!');
						}else{
							alert('error!');
						}
				}
			});
	   }else{
		   alert('Sorry , please check again!');
	   }
   })
   
   $('#trackall').click(function(){
	   $.ajax({
				type:'POST',
				url: 'querytask?action=all',
				dataType: "json",
				success:function(json){
						if(json.tasks){
							var tasks = json.tasks;
							$('#track_table').dataTable({
								"bPaginate":true,
							//	"sPaginationType": "full_numbers",
								"bDestroy":true,//重新加载是设置的属性
								"bProcessing":true,
								"aaData":tasks,
								"bLengthChange":false,
								"iDisplayLength": 10,
								"bFilter":false,
								"bSort":false,
							});
						}else{
							alert('error!');
						}
				}
	  });
   })
   
   $('#trackno').click(function(){
	   var no = trim($('#no_name').val());
	   if(no){
		   $.ajax({
				type:'POST',
				url: 'querytask?action=no',
				dataType: "json",
				data:{"no":no},
				success:function(json){
						if(json.tasks){
							var tasks = json.tasks;
							$('#track_table').dataTable({
								"bPaginate":true,
							//	"sPaginationType": "full_numbers",
								"bDestroy":true,//重新加载是设置的属性
								"bProcessing":true,
								"aaData":tasks,
								"bLengthChange":false,
								"iDisplayLength": 10,
								"bFilter":false,
								"bSort":false,
							});
						}else{
							alert('error!');
						}
				}
			});
	   }else{
		   alert('Please enter the no')
	   }
   })
   
   $('#trackname').click(function(){
	   var name = trim($('#no_name').val());
	   if(name){
		   $.ajax({
				type:'POST',
				url: 'querytask?action=name',
				dataType: "json",
				data:{"name":name},
				success:function(json){
						if(json.tasks){
							var tasks = json.tasks;
							$('#track_table').dataTable({
								"bPaginate":true,
							//	"sPaginationType": "full_numbers",
								"bDestroy":true,//重新加载是设置的属性
								"bProcessing":true,
								"aaData":tasks,
								"bLengthChange":false,
								"iDisplayLength": 10,
								"bFilter":false,
								"bSort":false,
							});
						}else{
							alert('error!');
						}
				}
			});
	   }else{
		   alert('Please enter the name')
	   }
   })
   
   $('#query_orders').click(function(){
	   $.ajax({
		  type:'GET',
		  url:'motoquery',
		  dataType:'json',
		  success:function(json){
			  if(json.orders){
					var orders = json.orders;
					$('#orders_table').dataTable({
						"bPaginate":true,
					//	"sPaginationType": "full_numbers",
						"bDestroy":true,//重新加载是设置的属性
						"bProcessing":true,
						"aaData":orders,
						"bLengthChange":false,
						"iDisplayLength": 10,
						"bFilter":false,
						"bSort":false,
					});
					$('#orders_table tbody tr').live("click",function(event){
						 var nTds = $('td', this);
						 var cno = $(nTds[1]).text();
						 var ino = $(nTds[2]).text();
						 $.ajax({
								type:'POST',
								url: 'motoquery',
								dataType: "json",
								data:{"cno":cno,"ino":ino},
								success:function(json){
										if(json){
											$('#pack_no').html(json.pack_no);
											$('#pack_shipper').html(json.pack_shipper);
											$('#pack_cno').html(json.pack_cno);
											$('#pack_ov').html(json.pack_ov);
											$('#pack_cargo').html(json.pack_cargo);
											$('#pack_boxes').html(json.pack_boxes);
											$('#pack_quantity').html(json.pack_quantity);
											$('#pack_up').html(json.pack_up);
											$('#pack_tp').html(json.pack_tp);
											$('#pack_uv').html(json.pack_uv);
											$('#pack_tv').html(json.pack_tv);
											$('#pack_tw').html(json.pack_tw);
											$('#pack_poo').html(json.pack_poo);
											$('#pack_date').html(json.pack_date);
											
											$('#eir_company').html(json.inter_company);
											$('#eir_user').html(json.inter_user);
											$('#eir_pod').html(json.inter_dp);
											$('#eir_dt').html(json.inter_dt);
											$('#eir_por').html(json.inter_rp);
											$('#eir_vess').html(json.inter_voy);
											$('#eir_cno').html(json.inter_cno);
											$('#eir_st').html(json.inter_size);
											$('#eir_optr').html(json.inter_optr);
											$('#eir_seal').html(json.inter_seal);
											$('#eir_truck').html(json.inter_truk);
											$('#eir_pout').html(json.inter_pout);
											$('#eir_pin').html(json.inter_pin);
											$('#eir_timeout').html(json.inter_timeout);
										}else{
											alert('query error!');
										}
								}
							});
					}).live("mouseover",function(){
						$(this).addClass('books_col');
					}).live("mouseout",function(){
						$(this).removeClass('books_col');
					});
				}else{
					alert('no orders!');
				}
		  }
	   });
   })
   
   /*
    * end of motohome.js
    */
   
   /*
    * lagenthome.js
    */
   
   $('#query_book').click(function(){
	   $.ajax({
			type:'GET',
			url: 'query',
			dataType: "json",
			success:function(json){
					if(json.bookings){
						var bookings = json.bookings;
						$('#booking_table').dataTable({
							"bPaginate":true,
						//	"sPaginationType": "full_numbers",
							"bDestroy":true,
							"bProcessing":true,
							"aaData":bookings,
							"bLengthChange":false,
							"iDisplayLength": 10,
							"bFilter":false,
							"bSort":false,
						});
						$('#booking_table tbody tr').live("click",function(event){
							 var nTds = $('td', this);
							 var id = $(nTds[0]).text();
							 $.ajax({
									type:'POST',
									url: 'query',
									dataType: "json",
									data:{"id":id},
									success:function(json){
											if(json){
												$('#book_shipper').html(json.shipper);
												$('#book_con').html(json.consignee);
												$('#book_notify').html(json.notifyparty);
												$('#book_place').html(json.placeofreceipt);
												$('#book_load').html(json.portofloading);
												$('#book_ocean').html(json.oceanvessel);
												$('#book_dis').html(json.portofdischarge);
												$('#book_del').html(json.placeofdelivery);
												$('#book_mn').html(json.mark);
												$('#book_np').html(json.pkgs);
												$('#book_td').html(json.type);
												$('#book_gw').html(json.kgs);
												$('#book_m3').html(json.m3);
											}else{
												alert('query error!');
											}
									}
								});
						}).live("mouseover",function(){
							$(this).addClass('books_col');
						}).live("mouseout",function(){
							$(this).removeClass('books_col');
						});
					}else{
						alert('error!');
					}
			}
		});
   })
   
   $('#book_confirm').click(function(){
	   var no = trim($('#book_no').val());
	   if(no){
		   $.ajax({
				type:'POST',
				url: 'confirm',
				dataType: "json",
				data:{"no":no},
				success:function(json){
						if(json.success == 1){
							alert('Confirm success!');
						}else{
							alert('query error!');
						}
				}
			});
	   }else{
		   alert('Please check the no!');
	   }
   })
   
   $('#book_refuse').click(function(){
	   $.ajax({
			type:'GET',
			url: 'confirm',
			dataType: "json",
			success:function(json){
					if(json.success == 1){
						alert('Refuse success!');
					}else{
						alert('Refuse error!');
					}
			}
		});
   })
   
   $('#iter_send').click(function(){
	   var company = trim($('#company').val()),no = trim($('#no').val()),user = trim($('#cuser').val()),pod = trim($('#pod').val()),dt = trim($('#dt').val()),por = trim($('#por').val()),
	   		vess = trim($('#vess').val()),cno = trim($('#cno').val()),size = trim($('#size').val()),optr = trim($('#optr').val()),seal = trim($('#seal').val()),
	   		truck = trim($('#truck').val()),pout = trim($('#pout').val()),pin = trim($('#pin').val()),timeout = trim($('#timeout').val()),sagentEmail = trim($('#sagentEmail').val());
	   
	   if(company && no && user && pod && dt && por && vess && cno && size && optr && seal && truck && pout && pin && timeout && sagentEmail){
		   $.ajax({
				type:'POST',
				url: 'linerinter',
				dataType: "json",
				data:{"company":company,"no":no,"user":user,"pod":pod,"dt":dt,"por":por,"vess":vess,
					"cno":cno,"size":size,"optr":optr,"seal":seal,"truck":truck,"pout":pout,"pin":pin,
					"timeout":timeout,"sagentEmail":sagentEmail},
				success:function(json){
						if(json.success == 1){
							alert('Send success!');
						}else{
							alert('Send error!');
						}
				}
			});
	   }else{
		   alert('Please check again!');
	   }
   })
   
   $('#bill_send').click(function(){
	   var com = trim($('#bill_com').val()),con = trim($('#bill_con').val()),name = trim($('#bill_name').val()),addr = trim($('#bill_addr').val()),bank = trim($('#bill_bank').val()),account = trim($('#bill_account').val()),vess = trim($('#bill_vess').val()),
	   voy = trim($('#bill_voy').val()),pol = trim($('#bill_pol').val()),pod = trim($('#bill_pod').val()),no = trim($('#bill_no').val()),dp = trim($('#bill_dp').val()),
	   ocean = trim($('#bill_ocean').val()),pou = trim($('#bill_pou').val()),ad = trim($('#bill_ad').val()),iyd = trim($('#bill_iyd').val()),
	   mark = trim($('#bill_mark').val()),cargo = trim($('#bill_cargo').val()),quantity = trim($('#bill_quantity').val()),
	   kg = trim($('#bill_kg').val()),vol = trim($('#bill_vol').val()),agentemail = trim($('#bill_agentemail').val());
	  
	  if(com && con && name && addr && bank && account && vess && voy && pol && pod && no && dp && ocean && pou && ad && iyd &&
			  mark && cargo && quantity && kg && vol && agentemail){
		   $.ajax({
				type:'POST',
				url: 'linerbill',
				dataType: "json",
				data:{"com":com,"con":con,"name":name,"addr":addr,"bank":bank,"account":account,"vess":vess,"voy":voy,
					"pol":pol,"pod":pod,"no":no,"dp":dp,"ocean":ocean,"pou":pou,"ad":ad,
					"iyd":iyd,"mark":mark,"cargo":cargo,"quantity":quantity,"kg":kg,"vol":vol,
					"agentemail":agentemail},
				success:function(json){
						if(json.success == 1){
							alert('Send success!');
						}else{
							alert('Send error!');
						}
				}
			});
	  }else{
		   alert('Please check again!');
	  }
   })
   
   $('#query_cfd').click(function(){
	   $.ajax({
			type:'GET',
			url: 'shippment',
			dataType: "json",
			success:function(json){
					if(json.confirmeds){
						var confirmeds = json.confirmeds;
						$('#cfd_table').dataTable({
							"bPaginate":true,
						//	"sPaginationType": "full_numbers",
							"bDestroy":true,
							"bProcessing":true,
							"aaData":confirmeds,
							"bLengthChange":false,
							"iDisplayLength": 10,
							"bFilter":false,
							"bSort":false,
						});
						$('#cfd_table tbody tr').live("click",function(event){
							 $('#sendinfo').modal('show');
							 var nTds = $('td', this);
							 var no = $(nTds[0]).text();
							 var email = $(nTds[4]).text();
							 $('#sam').html(email);
							 $('#mno').html(no);
						}).live("mouseover",function(){
							$(this).addClass('books_col');
						}).live("mouseout",function(){
							$(this).removeClass('books_col');
						});
					}else{
						alert('error!');
					}
			}
		});
   })
   
   $('#lasend').click(function(){
	   var no = $('#mno').html(),
		 email = $('#sam').html(),
		 info_area = $('#info_area').val();
	   if(trim(info_area)){
		   $.ajax({
				type:'POST',
				url: 'shippment',
				dataType: "json",
				data:{"no":no,"sagentEmail":email,"info":info_area},
				success:function(json){
						if(json.success == 1){
							$('#sendinfo').modal('hide');
						}else{
							alert('send error!');
						}
				}
			});
	   }else{
		   alert('Please check it!');
	   }
   })
   
   $('#lacancel').click(function(){
	   $('#sendinfo').modal('hide');
   })
   
   /*
    * end of lagenthome.js
    */
   
   /*
    * shipperhome.js
    */
   $('#inquiry_send').click(function(){
	   var no = trim($('#inquiry_no').val()),
	   shipper = trim($('#inquiry_shipper').val()),
	   shipper_email = trim($('#inquiry_shipper_email').val()),
	   departure = trim($('#inquiry_departure').val()),
	   dest = trim($('#inquiry_dest').val()),
	   cargo = trim($('#inquiry_cargo').val()),
	   weight = trim($('#inquiry_weight').val()),
	   m3 = trim($('#inquiry_m3').val()),
	   info = trim($('#inquiry_info').val()),
	   agents = trim($('#inquiry_sagents').val());
	   if(no && shipper && shipper_email && departure && dest && cargo && weight && m3 && info && agents){
		   $.ajax({
				type:'POST',
				url: 'inquiry',
				dataType: "json",
				data:{"no":no,"shipper":shipper,"shipper_email":shipper_email,"departure":departure,"dest":dest,
					"cargo":cargo,"weight":weight,"m3":m3,"info":info,"agents":agents},
				success:function(json){
						if(json.success == 1){
							alert('send success!');
						}else{
							alert('send error!');
						}
				}
			});
	   }else{
		   alert('Please check it again!');
	   }
   })
   
   $('#cargo_send').click(function(){
	   var no = trim($('#cargo_no').val()),shipper = trim($('#cargo_shipper').val()),shipper_addr = trim($('#cargo_shipper_address').val()),
	   		con = trim($('#cargo_con').val()),con_addr = trim($('#cargo_con_addr').val()),departure = trim($('#cargo_departure').val()),
	   		dest = trim($('#cargo_dest').val()),spec = trim($('#cargo_spec').val()),name = trim($('#cargo_name').val()),pieces = trim($('#cargo_pieces').val()),
	   		weight = trim($('#cargo_weight').val()),m3 = trim($('#cargo_m3').val()),charges = trim($('#cargo_charges').val()),semail = trim($('#cargo_shipper_email').val()),
	   		saemail = trim($('#cargo_sagent_email').val());
	   if(no && shipper && shipper_addr && con && con_addr && departure && dest && spec && name && pieces && weight && charges && m3 && semail && saemail){
		   $.ajax({
				type:'POST',
				url: 'cargo',
				dataType: "json",
				data:{"no":no,"shipper":shipper,"shipper_addr":shipper_addr,"con":con,"dest":dest,
					"con_addr":con_addr,"departure":departure,"spec":spec,"name":name,"pieces":pieces,"weight":weight,
					"m3":m3,"charges":charges,"semail":semail,"saemail":saemail},
				success:function(json){
						if(json.success == 1){
							alert('send success!');
						}else{
							alert('send error!');
						}
				}
			});
	   }else{
		   alert('Please check it again!');
	   }
   })
   
   $('#query_bill').click(function(){
	   $.ajax({
			type:'GET',
			url: 'querybill',
			dataType: "json",
			success:function(json){
					if(json.bills){
						var bills = json.bills;
						$('#bill_table').dataTable({
							"bPaginate":true,
						//	"sPaginationType": "full_numbers",
							"bDestroy":true,
							"bProcessing":true,
							"aaData":bills,
							"bLengthChange":false,
							"iDisplayLength": 10,
							"bFilter":false,
							"bSort":true,
						});
						$('#bill_table tbody tr').live("click",function(event){
							 var nTds = $('td', this);
							 var no = $(nTds[0]).text();
							 $.ajax({
									type:'POST',
									url: 'querybill',
									dataType: "json",
									data:{"no":no},
									success:function(json){
											if(json){
												$('#bill_company').html(json.company);
												$('#bill_name').html(json.conName);
												$('#bill_bank').html(json.bank);
												$('#bill_addr').html(json.conAddr);
												$('#bill_account').html(json.account);
												$('#bill_vess').html(json.vess);
												$('#bill_voy').html(json.voy);
												$('#bill_pol').html(json.pol);
												$('#bill_dest').html(json.dest);
												$('#bill_no').html(json.no);
												$('#bill_dp').html(json.dp);
												$('#bill_ocean').html(json.ocean);
												$('#bill_pou').html(json.pou);
												$('#bill_ad').html(json.ad);
												$('#bill_iyd').html(json.iyd);
												$('#bill_mark').html(json.mark);
												$('#bill_quantity').html(json.quantity);
												$('#bill_weight').html(json.weight);
												$('#bill_m3').html(json.volume);
												$('#bill_saemail').html(json.sagentEmail);
												$('#bill_semail').html(json.sEmail);
											}else{
												alert('query error!');
											}
									}
								});
						}).live("mouseover",function(){
							$(this).addClass('books_col');
						}).live("mouseout",function(){
							$(this).removeClass('books_col');
						});
					}else{
						alert('no bills!');
					}
			}
		});
   })
   
   $('#select_sagent').click(function(){
	   $('#sagents_info').modal('show');
	   $('#agents_list tbody').empty();
	   //read the list of shipping agents
	   $.ajax({
		  type:'GET',
		  url:'querysagents',
		  dataType:'json',
		  success:function(json){
			  if(json.agents){
				  var agents = json.agents;
				  agentsArray = {};
				  $('#agents_list').dataTable({
						"bPaginate":true,
					//	"sPaginationType": "full_numbers",
						"bDestroy":true,
						"bProcessing":true,
						"aaData":agents,
						"bLengthChange":false,
						"iDisplayLength": 10,
						"bFilter":false,
						"bSort":true,
				 });
				  $('#agents_list tbody tr').on("click",function(event){
						 var nTds = $('td', this);
						 var email = $(nTds[1]).text();
						 if($(this).hasClass('books_selected')){
							 $(this).removeClass('books_selected');
							 agentsArray[email] = null;
						 }else{
							 $(this).addClass('books_selected');
							 agentsArray[email] = email;
						 }
					}).live("mouseover",function(){
						$(this).addClass('books_col');
					}).live("mouseout",function(){
						$(this).removeClass('books_col');
					});
			  }else{
				  alert('no shipping agents!');
			  }
		  }
	   });
   })
   var agentsArray;
   
   $('#sagents_info_cancel').click(function(){
	   $('#sagents_info').modal('hide');
	   agentsArray = null;
   })
   
   $('#sagents_info_confirm').click(function(){
	   if(agentsArray){
		   var str = '';
		   for( var key in agentsArray){
			   str += agentsArray[key]+' ';
		   }
		   $('#inquiry_sagents').html(str);
	   }
	   $('#sagents_info').modal('hide');
	   agentsArray = null;
   })
   /*
    * end of shipperhome.js
    */
   
   /*
    * shippingAgenthome.js
    */
   
   $('#send_booking').click(function(){
	   var shipper = trim($('#booking_shipper').val()),con = trim($('#booking_con').val()),np = trim($('#booking_np').val())
	   		por = trim($('#booking_por').val()),pol = trim($('#booking_ov').val()),ov = trim($('#booking_ov').val()),
	   		podis = trim($('#booking_podis').val()),podel=trim($('#booking_podel').val()),mark=trim($('#booking_mark').val()),
	   		quantity = trim($('#booking_quantity').val()),cargo=trim($('#booking_cargo').val()),weight=trim($('#booking_weight').val()),
	   		m3 = trim($('#booking_m3').val()),lae = trim($('#booking_lae').val());
	   
	   if(shipper && con && np && por && pol && ov && podis && podel && mark && quantity && cargo && weight && m3 && lae){
		   $.ajax({
				type:'POST',
				url: 'addbooking',
				dataType: "json",
				data:{"shipper":shipper,"con":con,"np":np,"por":por,"pol":pol,
					"ov":ov,"podis":podis,"podel":podel,"mark":mark,"quantity":quantity,"cargo":cargo,
					"weight":weight,"m3":m3,"lae":lae},
				success:function(json){
						if(json.success == 1){
							alert('send success!');
						}else{
							alert('send error!');
						}
				}
			});
	   }else{
		   alert('Sorry, please check it again!');
	   }
   })
   
   $('#query_inquiry').click(function(){
	   $.ajax({
			type:'GET',
			url: 'queryInquiry',
			dataType: "json",
			success:function(json){
					if(json.inquiries){
						var inquiries = json.inquiries;
						$('#inquiry_table').dataTable({
							"bPaginate":true,
						//	"sPaginationType": "full_numbers",
							"bDestroy":true,
							"bProcessing":true,
							"aaData":inquiries,
							"bLengthChange":false,
							"iDisplayLength": 15,
							"bFilter":false,
							"bSort":true,
						});
						$('#inquiry_table tbody tr').live("click",function(event){
							 var nTds = $('td', this);
							 var no = $(nTds[0]).text();
							 $('#inquiry_info').modal('show');
							 $.ajax({
									type:'POST',
									url: 'queryInquiry?action=get',
									dataType: "json",
									data:{"no":no},
									success:function(json){
											if(json){
												$('#inquiry_info_no').html(json.no);
												$('#inquiry_info_shipper').html(json.shipper);
												$('#inquiry_info_email').html(json.shipperEmail);
												$('#inquiry_info_departure').html(json.departure);
												$('#inquiry_info_dest').html(json.destination);
												$('#inquiry_info_cargo').html(json.cargo);
												$('#inquiry_info_weight').html(json.weight);
												$('#inquiry_info_m3').html(json.volume);
												$('#inquiry_info_info').html(json.info);
											}else{
												alert('query error!');
											}
									}
								});
						}).live("mouseover",function(){
							$(this).addClass('books_col');
						}).live("mouseout",function(){
							$(this).removeClass('books_col');
						});
					}else{
						alert('no inquiries!');
					}
			}
		});
   })
   
   $('#inquiry_cancel').click(function(){
	   var no = $('#inquiry_info_no').html();
	   $.ajax({
			type:'POST',
			url: 'queryInquiry?action=update',
			dataType: "json",
			data:{"no":no},
			success:function(json){
					if(json.success == 1){
						$('#inquiry_info').modal('hide');
					}else{
						$('#inquiry_info').modal('hide');
					}
			}
		});
   })
   
   $('#inquiry_ok').click(function(){
	   $('#inquiry_info').modal('hide');
   })
   
   $('#query_cargo').click(function(){
	   $.ajax({
			type:'GET',
			url: 'queryCargo',
			dataType: "json",
			success:function(json){
					if(json.cargos){
						var cargos = json.cargos;
						$('#cargo_table').dataTable({
							"bPaginate":true,
						//	"sPaginationType": "full_numbers",
							"bDestroy":true,
							"bProcessing":true,
							"aaData":cargos,
							"bLengthChange":false,
							"iDisplayLength": 15,
							"bFilter":false,
							"bSort":true,
						});
						$('#cargo_table tbody tr').live("click",function(event){
							 var nTds = $('td', this);
							 var no = $(nTds[0]).text();
							 $('#cargo_info').modal('show');
							 $.ajax({
									type:'POST',
									url: 'queryCargo?action=get',
									dataType: "json",
									data:{"no":no},
									success:function(json){
											if(json){
												$('#cargo_info_no').html(json.no);
												$('#cargo_info_shipper').html(json.shipper);
												$('#cargo_info_addr').html(json.addr);
												$('#cargo_info_email').html(json.email);
												$('#cargo_info_con').html(json.con);
												$('#cargo_info_con_addr').html(json.conAddr);
												$('#cargo_info_departure').html(json.departure);
												$('#cargo_info_dest').html(json.dest);
												$('#cargo_info_spec').html(json.spec);
												$('#cargo_info_cargo').html(json.cargo);
												$('#cargo_info_pieces').html(json.pieces);
												$('#cargo_info_weight').html(json.weight);
												$('#cargo_info_m3').html(json.m3);
												$('#cargo_info_charges').html(json.charges);
											}else{
												alert('query error!');
											}
									}
								});
						}).live("mouseover",function(){
							$(this).addClass('books_col');
						}).live("mouseout",function(){
							$(this).removeClass('books_col');
						});
					}else{
						alert('no cargos!');
					}
			}
		});
   })
   
   $('#cargo_confirm').click(function(){
	   var no = $('#cargo_info_no').html();
	   $.ajax({
			type:'POST',
			url: 'queryCargo?action=update',
			dataType: "json",
			data:{"no":no},
			success:function(json){
					if(json.success == 1){
						$('#cargo_info').modal('hide');
					}else{
						$('#cargo_info').modal('hide');
					}
			}
		});
   })
   
   $('#cargo_cancel').click(function(){
	   $('#cargo_info').modal('hide');
   })
   
   $('#query_forward_bill').click(function(){
	   $.ajax({
			type:'GET',
			url: 'billforward',
			dataType: "json",
			success:function(json){
					if(json.bills){
						var bills = json.bills;
						$('#forward_bill_table').dataTable({
							"bPaginate":true,
						//	"sPaginationType": "full_numbers",
							"bDestroy":true,
							"bProcessing":true,
							"aaData":bills,
							"bLengthChange":false,
							"iDisplayLength": 15,
							"bFilter":false,
							"bSort":true,
						});
						$('#forward_bill_table tbody tr').live("click",function(event){
							 var nTds = $('td', this);
							 var no = $(nTds[0]).text();
							 $('#bill_forward_info').modal('show');
							 $('#bill_forward_no').html(no);
						}).live("mouseover",function(){
							$(this).addClass('books_col');
						}).live("mouseout",function(){
							$(this).removeClass('books_col');
						});
					}else{
						alert('no cargos!');
					}
			}
		});
   })
   
   $('#bill_forward_confirm').click(function(){
	   var no = $('#bill_forward_info').html(),
	   		shipperEmail = trim($('#bill_forward_shipperEmail').val());
	   if(no){
		   $.ajax({
				type:'POST',
				url: 'billforward',
				dataType: "json",
				data:{"no":no,"shipperEmail":shipperEmail},
				success:function(json){
						if(json.success == 1){
							$('#bill_forward_info').modal('hide');
						}else{
							alert('error!');
						}
				}
			});
	   }else{
		   alert('Please check it again!');
	   }
   })
   
   $('#bill_forward_cancel').click(function(){
	   $('#bill_forward_info').modal('hide');
   })
   
   
   $('#shippment_query').click(function(){
	   $.ajax({
			type:'GET',
			url: 'shippmentquery',
			dataType: "json",
			success:function(json){
					if(json.inters){
						var inters = json.inters;
						$('#shippment_table').dataTable({
							"bPaginate":true,
						//	"sPaginationType": "full_numbers",
							"bDestroy":true,
							"bProcessing":true,
							"aaData":inters,
							"bLengthChange":false,
							"iDisplayLength": 15,
							"bFilter":false,
							"bSort":true,
						});
						$('#shippment_table tbody tr').live("click",function(event){
							 var nTds = $('td', this);
							 var no = $(nTds[0]).text();
							 $('#Shippment_info').modal('show');
							 $('#shippment_inter_no').html(no);
						}).live("mouseover",function(){
							$(this).addClass('books_col');
						}).live("mouseout",function(){
							$(this).removeClass('books_col');
						});
					}else{
						alert('no cargos!');
					}
			}
		});
   })
   
   $('#shippment_send').click(function(){
	   var inter_no = $('#shippment_inter_no').html(),
	   		motoEmail = trim($('#shippment_info_moto_email').val()),
	   		no = trim($('#shippment_info_no').val()),
	   		shipper = trim($('#shippment_info_shipper').val()),
	   		cno = trim($('#shippment_info_cno').val()),
	   		ov = trim($('#shippment_info_ov').val()),
	   		cargo = trim($('#shippment_info_cargo').val()),
	   		boxes = trim($('#shippment_info_boxes').val()),
	   		quantity = trim($('#shippment_info_quantity').val()),
	   		up = trim($('#shippment_info_up').val()),
	   		tp = trim($('#shippment_info_tp').val()),
	   		uv = trim($('#shippment_info_uv').val()),
	   		tv = trim($('#shippment_info_tv').val()),
	   		tw = trim($('#shippment_info_tw').val()),
	   		poo = trim($('#shippment_info_poo').val());
	   		
	   if(inter_no && motoEmail && no && shipper && cno && ov && cargo && boxes && quantity && up && tp && uv && tv && tw && poo){
		   $.ajax({
				type:'POST',
				url: 'shippmentquery',
				dataType: "json",
				data:{"inter_no":inter_no,"motoEmail": motoEmail,"no":no,"shipper": shipper,"cno": cno,"ov": ov,"cargo": cargo, 
					"boxes":boxes,"quantity": quantity, "up":up,"tp": tp,"uv": uv,"tv": tv,"tw" : tw, "poo": poo},
				success:function(json){
						if(json.success == 1){
							$('#Shippment_info').modal('hide');
						}else{
							alert('error!');
						}
				}
			});
	   }else{
		   alert('Please check it again!');
	   }
   })
   
   $('#shippment_cancel').click(function(){
	   $('#Shippment_info').modal('hide');
   })
   
   $('#query_shipment_info').click(function(){
	   $.ajax({
			type:'GET',
			url: 'queryshipinfo',
			dataType: "json",
			success:function(json){
					if(json.infos){
						var infos = json.infos;
						$('#shippment_info_table').dataTable({
							"bPaginate":true,
						//	"sPaginationType": "full_numbers",
							"bDestroy":true,
							"bProcessing":true,
							"aaData":infos,
							"bLengthChange":false,
							"iDisplayLength": 15,
							"bFilter":false,
							"bSort":true,
						});
					}else{
						alert('no shipment information!');
					}
			}
		});
   })
   
   /*
    * end of shippingAgenthome.js
    */
})
